﻿using System;
using System.Web;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using NewLife.Reflection;
using XCode;
using System.Diagnostics;
using NewLife.Web;

namespace BingZi.HY.Core
{
    /// <summary>
    /// 模版基类(模版参数之类)
    /// </summary>
    public class BaseTemplatePage:BasePage
    {

        #region "属性"


        private String _TemplateName = "Default";
        /// <summary>
        /// 模版名称
        /// </summary>
        public String TemplateName
        {
            get { return _TemplateName; }
            set { _TemplateName = value; }
        }


        /// <summary>
        /// 模版路径
        /// </summary>
        public String TemplatePath
        {
            get { return  String.Format("/Templates/{0}/", TemplateName); }
        }

        

        /// <summary>
        /// 模版缓存时间
        /// </summary>
        public Int64 Template_CacheTime
        {
            get { return SiteSettings.Template_CacheTime; }
        }

        /// <summary>
        /// 模版缓存是否开启
        /// </summary>
        public Boolean Template_CacheEnable
        {
            get { return SiteSettings.Template_CacheEnable; }
        }


        private Hashtable _Template_Puts = new Hashtable();
        /// <summary>
        /// 模版参数(临时用)
        /// </summary>
        public Hashtable Template_Puts
        {
            get { return _Template_Puts; }
            set { _Template_Puts = value; }
        }

        /// <summary>
        /// 信息类型
        /// </summary>
        public String InfoType = WebHelper.GetStringParam(HttpContext.Current.Request, "InfoType", "sale");



        #endregion





        #region "站点属性"


        private String _BasePage_Title = String.Empty;
        /// <summary>
        /// 基础页面标题
        /// </summary>
        public String BasePage_Title
        {
            get { return _BasePage_Title; }
            set { _BasePage_Title = value; }
        }

       


        /// <summary>
        /// 页面标题
        /// </summary>
        public String Page_Title
        {
            get { return BasePage_Title + SiteSettings.Site_Title; }
        }

        /// <summary>
        /// 页面关键字
        /// </summary>
        public String Page_MetaKeywords
        {
            get { return SiteSettings.Site_MetaKeywords; }
        }

        /// <summary>
        /// 页面描述
        /// </summary>
        public String Page_MetaDescription
        {
            get { return SiteSettings.Site_MetaDescription; }
        }

        /// <summary>
        /// 页面版权
        /// </summary>
        public String Page_Copyright
        {
            get { return SiteSettings.Site_Copyright; }
        }

        /// <summary>
        /// 页面后缀
        /// </summary>
        public String Page_Suffix
        {
            get { return SiteSettings.Site_Suffix; }
        }



 
        /// <summary>
        /// 站点设置
        /// </summary>
        public sys_SystemInfo SiteSettings
        {
            get{ return FrameSystemInfo.GetSystemInfoTable;  }
        }

    



        #endregion


        #region "菜单加载相关"
 
 
        



        #endregion



        #region "绑定模版文件"
        /// <summary>
        /// 显示模版
        /// </summary>
        /// <param name="ThemeType"></param>
        /// <param name="Puts"></param>
        /// <returns></returns>
        public String ViewTemplate(EnumTemplateFile TemplateFile, Hashtable Puts)
        {
            TemplateFormat xf = new TemplateFormat(this);
            return ViewTemplate(TemplateFile, Puts, xf);
        }

        /// <summary>
        /// 显示模版
        /// </summary>
        /// <param name="Theme"></param>
        /// <param name="ThemeFile"></param>
        /// <param name="Puts"></param>
        /// <returns></returns>
        public String ViewTemplate(String TemplateFile, Hashtable Puts)
        {
            TemplateFormat xf = new TemplateFormat(this);
            return ViewTemplate(TemplateFile, Puts, xf);
        }

        /// <summary>
        /// 显示模版
        /// </summary>
        /// <param name="Theme"></param>
        /// <param name="xf"></param>
        /// <param name="Puts"></param>
        /// <returns></returns>
        public String ViewTemplate(String TemplateFile, Hashtable Puts, TemplateFormat xf)
        {
            Stopwatch stopWatch = new Stopwatch();
            stopWatch.Start();
            //要测试的方法

            VelocityHelper vltContext = VelocityInstance.Instance(this);// new VelocityHelper(this);
            vltContext.Put("xf", xf);//模版格式化共用方法
            vltContext.Put("TemplatePath", TemplatePath);//模版格式化共用方法
        
            Template_Puts = Puts;
            if (Puts != null && Puts.Count > 0)
            {
                foreach (String key in Puts.Keys)
                {
                    vltContext.Put(key, Puts[key]);
                }
            }
     
            
            String templateString = vltContext.Display(TemplateFile);
            stopWatch.Stop();

           // FileTxtLogs.WriteLog(String.Format("[{1}]模板运行时间:{0}毫秒", stopWatch.ElapsedMilliseconds, TemplateFile), "运行时间");

            return templateString;
        }



        /// <summary>
        /// 显示模版
        /// </summary>
        /// <param name="Theme"></param>
        /// <param name="xf"></param>
        /// <param name="Puts"></param>
        /// <returns></returns>
        public String ViewTemplate(EnumTemplateFile TemplateFile, Hashtable Puts, TemplateFormat xf)
        {
            return ViewTemplate( EnumHelper.GetEnumTextVal((Int32)TemplateFile, typeof(EnumTemplateFile)), Puts, xf);
        }
        /// <summary>
        /// 显示模版
        /// </summary>
        /// <param name="Theme"></param>
        /// <param name="ThemeType"></param>
        /// <returns></returns>
        public String ViewTemplate(EnumTemplateFile TemplateFile)
        {
            return ViewTemplate(TemplateFile, new Hashtable());
        }


        #endregion



    }
}
